require 'qingcloud/sdk'

connector = QingCloud::SDK::Client::Connector.init('HTPPXGLAWLUDLRZTUQQQ', 'csb7DN36hLFt5FSrud77U3v2e6a0uUmLycIYxo38')

service = QingCloud::SDK::Client::Service.new connector

=begin
#(image_id:, instance_type: nil, cpu: nil, memory: nil, count: 1, instance_name: nil, login_mode:, login_keypair: nil, login_passwd: nil, vxnets_N: [], security_group: nil, volumes_N: [], need_newsid: nil, need_userdata: nil, userdata_type: nil, userdata_value: nil, userdata_path: nil,  zone:
run_inst_params= {
                  'image_id': 'centos66x64a',
                  'instance_type': 'c1m1',
                  'cpu': nil,
                  'memory': nil,
                  'count': 1,
                  'instance_name': "test123",
                  'login_mode': 'passwd',
                  'login_keypair': nil,
                  'login_passwd': 'Passw0rd!',
                  'vxnets_N': ['vxnet-jg716a6'],
                  'security_group': nil,
                  'volumes_N': [],
                  'need_newsid': nil,
                  'need_userdata': nil,
                  'userdata_type': nil,
                  'userdata_value': nil,
                  'userdata_path': nil,
                  'zone': 'pek2'
}
=end

#==================== describe back end server

#service.describe_load_balancer_backends(loadbalancer_backends_N: [], loadbalancer_listener: 'lbl-0of02vam', loadbalancer: nil, verbose: nil, offset: nil, limit: nil, zone: 'pek2')
service.describe_load_balancer_backends(loadbalancer_backends_N: ['lbb-m1mx7loi'], zone: 'pek2')

puts service.response

#==================== add back end server
=begin
#lbl-tbi6eqt2
#service.describe_load_balancers(loadbalancers_N: ['lb-0nawr55f'], status_N: ['active'], search_word: nil, verbose: nil, offset: nil, limit: nil, zone: 'pek2')
#{"action"=>"DescribeLoadBalancerBackendsResponse", "total_count"=>1, "loadbalancer_backend_set"=>[{"status"=>"down", "loadbalancer_backend_id"=>"lbb-equlgseg", "weight"=>1, "resource_id"=>"192.168.110.29", "loadbalancer_backend_name"=>"192.168.110.29", "loadbalancer_id"=>"lb-0nawr55f", "loadbalancer_policy_id"=>"lbp-kq1a1jq7", "disabled"=>0, "create_time"=>"2015-07-08T02:41:41Z", "owner"=>"usr-jyckCtDn", "loadbalancer_listener_id"=>"lbl-7xgx278j", "port"=>8080, "loadbalancer_policy_name"=>"kongyitest"}], "ret_code"=>0}

service.add_load_balancer_backends(loadbalancer_listener: 'lbl-tbi6eqt2', backends_N_resource_id: ['192.168.110.26'], backends_N_loadbalancer_backend_name: ['192.168.110.26'], backends_N_port: ['8080'], backends_N_weight: [1], listeners_N_listener_option: [], zone: 'pek2')

puts service.response
=end


#==================== descripbe loadbalance
=begin
service.describe_load_balancers(loadbalancers_N: ['lb-0nawr55f'], status_N: ['active'], search_word: nil, verbose: nil, offset: nil, limit: nil, zone: 'pek2')

puts service.response

=end
#==================== describe loadbalance listner
=begin
def add_load_balancer_listeners(
    loadbalancer:,
    listeners_N_listener_port:,
    listeners_N_listener_protocol:,
    listeners_N_backend_protocol:,
    listeners_N_loadbalancer_listener_name: [],
    listeners_N_balance_mode: [],
    listeners_N_session_sticky: [],
    listeners_N_forwardfor: [],
    listeners_N_healthy_check_method: [],
    listeners_N_healthy_check_option: [],
    listeners_N_listener_option: [],
    zone:)eval(build_fetch_match)
end
=end


#service.add_load_balancer_listeners(loadbalancer: 'lb-0nawr55f', listeners_N_listener_port: ['82'], listeners_N_listener_protocol: ['http'], listeners_N_backend_protocol: ['http'],zone: 'pek2')
#service.add_load_balancer_listeners(loadbalancer_listeners_N: [], loadbalancer: 'lb-0nawr55f', verbose: nil, offset: nil, limit: nil, zone: 'pek2')
=begin
def describe_load_balancer_listeners(
                    loadbalancer_listeners_N: [],
                    loadbalancer: nil,
                    verbose: nil,
                    offset: nil,
                    limit: nil,
                    zone:
                )eval(build_fetch_match)
                end 


puts service.response 
=end

=begin
service.describe_load_balancer_listeners(loadbalancer_listeners_N: ['lbl-tbi6eqt2'], zone: 'pek2')
puts service.response
=end

#==================== create a new vm
=begin
service.run_instances image_id: 'centos66x64a', 
                      instance_type: 'c1m1',
                      count: '2',
                      login_mode: 'passwd', 
                      login_passwd: 'Passw0rd!',
                      vxnets_N: ['vxnet-jg716a6'],                      
                      zone: 'pek2'



puts run_inst_params
service.run_instances run_inst_params

puts service.response

=end
#===================== descirbe a vm 
=begin
service.describe_instances(instances_N: ["i-rbd01srn", "i-jsjjpabp"], zone: 'pek2')

puts service.response

=end
#==================== stop a vm
=begin
service.stop_instances instances_N: ["i-rbd01srn", "i-jsjjpabp"], zone: 'pek2'

puts service.response
=end
#==================== start a vm
=begin
service.start_instances instances_N: ["i-rbd01srn", "i-jsjjpabp"], zone: 'pek2'

puts service.response
=end
#==================== delete a vm
=begin
service.terminate_instances instances_N: ["i-dr7a6wuy", "i-1wb1hffo"], zone: 'pek2'

puts service.response
=end

=begin
service.modify_load_balancer_backend_attributes(loadbalancer_backend: 'lbb-jva0lghf', disabled: 0, zone: 'pek2')
puts service.response
=end